<?php
if(!isset($_POST['lc'])) {
	die('No Direct Access');
}

require '../config.php';
include '../model/WeddingXML.class.php';

$x = new WeddingXML;

if( isset($_POST['lc']) && ($node = $x->checkCode($_POST['lc']))) {
	// Lets get us some names out
	$names= $node[0]->names->name;
	$namecount = count($names);

	$namestr = '';
	for($i=0; $i < $namecount; $i++) {
		list($first,$last) = explode(' ',(string)$names[$i]);
		if($i == 0 || $i != $namecount-1) {
			$namestr .= "$first, ";
		} else {
			$namestr = rtrim($namestr,', ');
			$namestr .= " & $first";
		}
	}

	//stick code in session for use later
	$_SESSION['lcode'] = (string)$node[0]->code;
	$_SESSION['names'] = $namestr;
	echo '1';
} else {
	echo '2';
}

